package org.ezplatform.office.meeting.common.service;

import java.util.ArrayList;
import java.util.List;

import org.ezplatform.core.data.DataInitialize;
import org.ezplatform.core.data.DataInitializeParam;
import org.ezplatform.office.meeting.setting.category.dao.BoardroomCategorySetDao;
import org.ezplatform.office.meeting.setting.category.entity.BoardroomCategorySet;
import org.ezplatform.office.meeting.setting.serve.dao.ServeSetDao;
import org.ezplatform.office.meeting.setting.serve.entity.ServeSet;
import org.springframework.beans.factory.annotation.Autowired;

public class MeetingInitService implements DataInitialize{
	
	@Autowired
	private BoardroomCategorySetDao boardroomCategorySetDao;
	
	@Autowired
	private ServeSetDao serveSetDao;
	
	@Override
	public boolean clearData(DataInitializeParam dp) {
		// TODO Auto-generated method stub
		String corpId = dp.getCorpId();
		this.boardroomCategorySetDao.delCategoryList(corpId, "1");
		this.serveSetDao.delServeSetSet(corpId, "1");
		return false;
	}

	@Override
	public boolean initData(DataInitializeParam dp) {
		// TODO Auto-generated method stub
		String corpId = dp.getCorpId();
		List<BoardroomCategorySet> categorySets = this.boardroomCategorySetDao.getCategoryList("0","1");
		if(categorySets!=null && categorySets.size()>0){
			List<BoardroomCategorySet> newCateList = new ArrayList<BoardroomCategorySet>();
			for(BoardroomCategorySet ct : categorySets){
				BoardroomCategorySet categorySet = new BoardroomCategorySet();
				categorySet.setCorpId(corpId);
				categorySet.setIsInit("1");
				categorySet.setName(ct.getName());
				categorySet.setSortNo(ct.getSortNo());
				newCateList.add(categorySet);
			}
			this.boardroomCategorySetDao.saveAll(newCateList);
		}
		List<ServeSet> serveSets = this.serveSetDao.getServeSetSet("0","1"); 
		if(serveSets!=null && serveSets.size()>0){
			List<ServeSet> newSetList = new ArrayList<ServeSet>();
			for(ServeSet ss : serveSets){
				ServeSet serveSet = new ServeSet();
				serveSet.setCorpId(corpId);
				serveSet.setIsInit("1");
				serveSet.setName(ss.getName());
				serveSet.setSortNo(ss.getSortNo());
				serveSet.setDescription(ss.getDescription());
				newSetList.add(serveSet);
			}
			this.serveSetDao.saveAll(newSetList);
		}
		return true;
	}

}
